package com.ruoyi.buss.grid.sh.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.utils.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.buss.grid.sh.domain.DataGtgshYz;
import com.ruoyi.buss.grid.sh.service.IDataGtgshYzService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;

/**
 * 优质商户Controller
 * 
 * @author ruoyi
 * @date 2021-07-09
 */
@RestController
@RequestMapping("/yzsh")
public class DataGtgshYzController extends BaseController
{
    @Autowired
    private IDataGtgshYzService dataGtgshYzService;

    /**
     * 查询优质商户列表
     */
    @PreAuthorize(hasPermi = "buss:yzsh:list")
    @GetMapping("/list")
    public TableDataInfo list(DataGtgshYz dataGtgshYz)
    {
        startPage("SJRQ DESC");
        dataGtgshYz.setSjrq(ListUtil.getSjrq(dataGtgshYz.getSjrq()));
        List<DataGtgshYz> list = dataGtgshYzService.selectDataGtgshYzList(dataGtgshYz);
        return getDataTable(list);
    }

    /**
     * 导出优质商户列表
     */
    @PreAuthorize(hasPermi = "buss:yzsh:export")
    @Log(title = "优质商户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataGtgshYz dataGtgshYz) throws IOException
    {
        dataGtgshYz.setSjrq(ListUtil.getSjrq(dataGtgshYz.getSjrq()));
        List<DataGtgshYz> list = dataGtgshYzService.selectDataGtgshYzList(dataGtgshYz);
        ExcelUtil<DataGtgshYz> util = new ExcelUtil<DataGtgshYz>(DataGtgshYz.class);
        util.exportExcel(response, list, "优质商户数据");
    }

    /**
     * 获取优质商户详细信息
     */
    @PreAuthorize(hasPermi = "buss:yzsh:query")
    @GetMapping(value = "/{deptid}")
    public AjaxResult getInfo(@PathVariable("deptid") String deptid)
    {
        return AjaxResult.success(dataGtgshYzService.selectDataGtgshYzById(deptid));
    }

    /**
     * 新增优质商户
     */
    @PreAuthorize(hasPermi = "buss:yzsh:add")
    @Log(title = "优质商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataGtgshYz dataGtgshYz)
    {
        dataGtgshYz.setSjrq(ListUtil.getSjrq(dataGtgshYz.getSjrq()));
        return toAjax(dataGtgshYzService.insertDataGtgshYz(dataGtgshYz));
    }

    /**
     * 修改优质商户
     */
    @PreAuthorize(hasPermi = "buss:yzsh:edit")
    @Log(title = "优质商户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataGtgshYz dataGtgshYz)
    {
        dataGtgshYz.setSjrq(ListUtil.getSjrq(dataGtgshYz.getSjrq()));
        return toAjax(dataGtgshYzService.updateDataGtgshYz(dataGtgshYz));
    }

    /**
     * 删除优质商户
     */
    @PreAuthorize(hasPermi = "buss:yzsh:remove")
    @Log(title = "优质商户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptids}")
    public AjaxResult remove(@PathVariable String[] deptids)
    {
        return toAjax(dataGtgshYzService.deleteDataGtgshYzByIds(deptids));
    }
}
